﻿var dialog;
$(function () {
    $("#txtTEMPERATURE").ligerTextBox({ number: true, precision: 1 });

    $(":radio").click(function (item) {
        var id = $(this).attr("name").replace("rdo", "");
        $("[id^=div" + id + "]").hide();
        $("#div" + id + $(this).val()).show();
    });

    dialog = frameElement.dialog;
    $("#lblPATIENT_NAME").text(dialog.get('data').BED_NO + "床\xa0\xa0\xa0\xa0" + dialog.get('data').PATIENT_NAME);
    $("#lblESCORT_NAME").text(dialog.get('data').ESCORT_NAME);
    $("#txtTEMPERATURE").val(dialog.get('data').TEMPERATURE);
    $('input:radio[name="rdoPROTECT_FLAG"][value=' + dialog.get('data').PROTECT_FLAG + ']').attr('checked', 'true').click();
    $('input:radio[name="rdoBREATH_FLAG"][value=' + dialog.get('data').BREATH_FLAG + ']').attr('checked', 'true').click();
    $('input:radio[name="rdoDIGESTION_FLAG"][value=' + dialog.get('data').DIGESTION_FLAG + ']').attr('checked', 'true').click();
    $("#txtPROTECT_TEXT").val(dialog.get('data').PROTECT_TEXT);
    $("#txtBREATH_TEXT").val(dialog.get('data').BREATH_TEXT);
    $("#txtDIGESTION_TEXT").val(dialog.get('data').DIGESTION_TEXT);
});

function save() {
    var id = $("#hdnId").val();
    var TEMPERATURE = $("#txtTEMPERATURE").val();
    var PROTECT_FLAG = $('input[name="rdoPROTECT_FLAG"]:checked').val();
    var PROTECT_TEXT = $("#txtPROTECT_TEXT").val();
    if (PROTECT_FLAG != 1) PROTECT_TEXT = "";
    var BREATH_FLAG = $('input[name="rdoBREATH_FLAG"]:checked').val();
    var BREATH_TEXT = $("#txtBREATH_TEXT").val();
    if (BREATH_FLAG != 1) BREATH_TEXT = "";
    var DIGESTION_FLAG = $('input[name="rdoDIGESTION_FLAG"]:checked').val();
    var DIGESTION_TEXT = $("#txtDIGESTION_TEXT").val();
    if (DIGESTION_FLAG != 1) DIGESTION_TEXT = "";
    var RID = IsEmpty(dialog.get('data').RID)?"":dialog.get('data').RID;

    if (IsEmpty(TEMPERATURE)) {
        $.ligerDialog.error("体温值不能为空");
        $("#txtTEMPERATURE").focus();
        return;
    }

    var jsonInfo = {
        RID: RID,
        PATROL_FLAG: 1,
        TEMPERATURE: TEMPERATURE,
        PROTECT_FLAG: PROTECT_FLAG,
        PROTECT_TEXT: PROTECT_TEXT,
        BREATH_FLAG: BREATH_FLAG,
        BREATH_TEXT: BREATH_TEXT,
        DIGESTION_FLAG: DIGESTION_FLAG,
        DIGESTION_TEXT: DIGESTION_TEXT
    };

    $.ajax({
        url: "/Escort/TodayTrajectory/Save",
        type: "post",
        data: {
            id: id,
            jsonInfo: JSON.stringify(jsonInfo)
        },
        success: function (r) {
            var r = $.parseJSON(r);
            if (r.Result == 1) {
                $.ligerDialog.success("保存成功", "",
                    function () {
                        parent.$("#btnSearch").click();
                        closeDialog();
                    }, { allowClose: false });
            }
            else if (r.Result == 0) {
                $.ligerDialog.error(r.Body);
            }
            else {
                $.ligerDialog.error("程序错误");
            }
        },
        error: function () {
            $.ligerDialog.error("程序错误");
        }
    });
}